//https://leetcode.cn/problems/delete-and-earn/submissions/584680917/

class Solution:
    def deleteAndEarn(self, nums: List[int]) -> int:
        cnt = Counter(nums)
        nums.sort()
        nums = list(set(nums))
        n = nums[-1]
        dp = [0, cnt[1]]
        for i in range(2, n+1):
            dp[0], dp[1] =dp[1] , max(dp[1], dp[0] + i * cnt[i])
        return dp[1]